package cn.itcast.bos.mq;

import java.io.UnsupportedEncodingException;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Service;

import cn.itcast.bos.mq.utils.SmsUtils;

/**
 * 项目短信的消费者
 * @author Administrator
 *
 */
@Service("smsConsumer")
public class SmsConsumer implements MessageListener{

	@Override
	public void onMessage(Message message) {
		//将信息转化为mapMessage
		MapMessage mapMessage=(MapMessage) message;
		
		//调用SMS服务发送短息
		try {
			//String result = SmsUtils.sendSmsByHTTP(mapMessage.getString("telephone"),mapMessage.getString("msg"));
		
			//返回信息如果是以000开头就说明发送成功

			//String result = SmsUtils.sendSmsByHTTP(model.getTelephone(), msg);
			String result="000/***";
			if (result.startsWith("000")) {
				//发送成功
				System.err.println("短信发送成功：手机号是："+mapMessage.getString("telephone")+"验证码相关信息是："+mapMessage.getString("msg"));
			}else {
				throw new RuntimeException("短信发送失败，信息码"+result);
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
